package com.site.utils;

import cn.hutool.core.convert.Convert;
import org.noear.redisx.RedisClient;
import org.noear.snack.ONode;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

@Component
public class RedisUtils {
    @Inject
    RedisClient redisClient;

    public <T> void put(String key, T value) {
        redisClient.getBucket().storeAndSerialize(key, value);
    }

    public <T> void put(String key, T value, int timeoutSeconds) {
        redisClient.getBucket().storeAndSerialize(key, value, timeoutSeconds);
    }

    public <T> ONode get(String key, Class<T> clz) {
        return ONode.load(redisClient.getBucket().getAndDeserialize(key, clz));
    }

    public <T> String getStr(String key, Class<T> clz) {
        return Convert.toStr(redisClient.getBucket().getAndDeserialize(key, clz));
    }
}
